<?php
/* 
 *入库详情
 */
class Enter_detailAction extends TransDetailAction {
    public function _filter(&$map) {
        $key = trim($_REQUEST['keywords']);
        if(!empty($key)) {
          if(strpos($key, ' ')) //高级搜索，仅搜索产品名称
            $map['_complex'] = A('Search')->search($key,'Product','name','Product.id');
          else{
            $where['Product.name'] = array('like',"%".$key."%");//产品名称
            //$where['Enter.enter_no'] = array('like',"%".$key."%");
            $where['_logic'] = "or";
            $map['_complex'] = $where; 
          }
        }
        if(!empty($_REQUEST['enter_id'])){
           $map['enter_id'] = $_REQUEST['enter_id'];
        }
        if(!empty($_REQUEST['enter_no'])){
            $where['Enter.enter_no'] = array('like',"%".trim($_REQUEST['enter_no'])."%");
        }
        if(!empty($_REQUEST['supplier_id'])){
           $map['supplier_id'] = $_REQUEST['supplier_id'];
        }
    }
    public function _before_index(){
        parent::_before_index();
        $this->assign('suppliers',getModelField('Supplier','id,name','sort'));
        $this->assign('users',getModelField('User'));
    }

    public function index(){
        $this->assign('meta_title','入库明细');
        parent::index('EnterView');
    }

    public function _before_add() {
        $supplier = M('Supplier')->where('status=1')->field('id,name')->findAll();
        $this->assign('supplier',$supplier);
    }

/*
    public function  _before_insert() {
        $_POST['product_id'] = empty ($_POST['ptm_id'])?(
                $_POST['product_id'] = empty ($_POST['ppy_id'])? 
                ($_POST['product_id'] = empty ($_POST['hz_id'])? 0:$_POST['hz_id'])
                    : $_POST['ppy_id'] ) : $_POST['ptm_id'];

        if($_POST['number'] < 1)
            $this->error("产品入库数量必须大于1");
        if(empty($_POST['enter_id']) )
            $this->error("必须选择入库单号");
    }*/
}
?>
